package projet_v1;

import java.util.List;

import projet_v1.simulation.Field;
import projet_v1.simulation.Location;

/**
 * Zombie class, derives from Character.
 * 
 * @author Antoine Lavail
 * 
 */

public class Zombie extends Character implements Actor {

	// Initial HP
	public static final int HP_ZOMBIES = 50;
	// Default speed
	private static final int SPEED = 1;

	/**
	 * Constructor of Zombie class.
	 * 
	 * @param healthPoints
	 *            initial HP
	 */
	public Zombie(int healthPoints) {
		super(healthPoints, Breed.ZOMBIE);
	}

	/**
	 * Another constructor of Zombie class. This one add a breed parameter.
	 * 
	 * @param healthPoints
	 *            : initial HP
	 * @param b
	 *            : the wanted breed.
	 */
	public Zombie(int healthPoints, Breed b) {
		super(healthPoints, b);
	}

	/**
	 * Another constructor of Zombie class. This one add a location for the
	 * zombie and the current field.
	 * 
	 * @param healthPoints
	 *            : initial HP.
	 * @param f
	 *            : the current field.
	 * @param l
	 *            : the wanted location of the zombie.
	 */
	public Zombie(int healthPoints, Field f, Location l) {
		super(healthPoints, Breed.ZOMBIE, f, l, SPEED);
	}

	/**
	 * Another constructor of Zombie class. This one add a location for the
	 * zombie and the current field. This one also add the breed parameter.
	 * 
	 * @param healthPoints
	 *            : initial HP.
	 * @param b
	 *            : the wanted breed.
	 * @param f
	 *            : the current field.
	 * @param l
	 *            : the wanted location of the zombie.
	 */
	protected Zombie(int healthPoints, Breed breed, Field f, Location l) {
		super(healthPoints, breed, f, l, SPEED);
	}

	/**
	 * Output a character's saying to the screen
	 * 
	 * @param str
	 *            what the character says
	 */
	public void say(String str) {
		System.out.println("Zombie says: BRAIIIIIINS!");
	}

	/**
	 * Method triggered on each character at the end of each turn.
	 */
	public void endOfTurn() {
		// Do nothing. Zombies are useless anyway...
	}

	/**
	 * The attack of the zombie on the encountered character.
	 * 
	 * @param c
	 *            : the character attacked.
	 */
	protected void attack(Character c) {
		if (c == null)
			throw new NullPointerException(
					"null character passed in attack method of zombie class.");
		c.reduceHealthPoints(35);// 30
		c.lastAttackedBy = this.getBreed();
	}

	/**
	 * Actions of a zombie when he encounter another character.
	 */
	public void encounterCharacter(Character c) {
		if (c == null)
			throw new NullPointerException(
					"null character passed in encounterCharacter method of zombie class.");
		if (c.getBreed().equals(Breed.HUMAN)) {
			attack(c);
		}
	}

	/**
	 * Make this character act ­ that is: make it do whatever it wants/needs to
	 * do.
	 * 
	 * @param currentField
	 *            The field currently occupied.
	 * @param updatedField
	 *            The field to transfer to.
	 * @param newActors
	 *            A list to add newly born character to.
	 */
	public void act(Field currentField, Field updatedField,
			List<Actor> newActors) {
		if (currentField == null)
			throw new NullPointerException(
					"null currentField passed in act method of human class.");
		if (updatedField == null)
			throw new NullPointerException(
					"null updatedField passed in act method of human class.");

		if (isAlive()) {
			List<Character> l = aroundCharacter(updatedField);
			for (Character character : l) {
				if (character.getBreed().equals(Breed.HUMAN)) {
					if (!((Human) character).getHasBeenBitten()) {
						attack(character);
						break;
					}
				}
			}

			Location newLocation = updatedField.freeAdjacentLocation(
					getLocation(), SPEED);
			if (newLocation != null) {
				setLocation(newLocation);
				updatedField.place(this, newLocation);
			}
		}
	}
}
